package com.hhkj.admin.sale.service.extend.impl;

import com.hhkj.admin.common.cont.NumTypeEnum;
import com.ruoyi.common.utils.num.NumUtils;
import com.hhkj.admin.sale.common.cont.withdrawal.WithdrawalStatusEnum;
import com.hhkj.admin.sale.domain.SaleWithdrawal;
import com.hhkj.admin.sale.model.dopo.SaleWithdrawalDo;
import com.hhkj.admin.sale.model.dopo.SaleWithdrawalPo;
import com.hhkj.admin.sale.service.base.SaleWithdrawalService;
import com.hhkj.admin.sale.service.extend.SaleWithdrawalExtendService;
import com.ruoyi.common.base.biz.service.extend.BaseExtendServiceImpl;
import com.ruoyi.common.cont.SysConst;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SaleWithdrawalExtendServiceImpl
        extends BaseExtendServiceImpl<SaleWithdrawal, SaleWithdrawalDo, SaleWithdrawalPo, SaleWithdrawalService>
        implements SaleWithdrawalExtendService {

    @Override
    public synchronized boolean save(SaleWithdrawalDo withdrawalDo) {
        long countTotalAmount = this.getService().count();
        String num = NumUtils.generateNum(NumTypeEnum.WITHDRAWAL.getPrefix(), ++countTotalAmount);
        withdrawalDo.setNum(num);
        // 提供默认值
        withdrawalDo.setSubmitTime(new Date());
        withdrawalDo.setCompleteFlag(SysConst.Flag.NO.getFlag());
        withdrawalDo.setStatusCode(WithdrawalStatusEnum.NORMAL.getCode());
        return this.getService().save(withdrawalDo);
    }
}
